package eg.ci.mvn.service.api.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


/**
 * BaseResponse
 *
 * @param <T> 实体
 * @author dev
 */
@NoArgsConstructor
@Getter
@Setter
@Schema(description = "返回说明")
@ApiModel(value = "返回说明")
public class BaseResponse<T> {

    /**
     * 业务码  详见ResponseType
     */
    @Schema(description = "业务处理编码,200成功,其它失败", example = "200", requiredMode = Schema.RequiredMode.REQUIRED)
    @ApiModelProperty(value = "业务处理编码,200成功,其它失败")
    private String code;

    /**
     * 信息
     */
	@Schema(description = "描述信息")
    @ApiModelProperty(value = "描述信息")
    private String message;

    /**
     * 数据
     */
	@Schema(description = "数据")
    @ApiModelProperty(value = "数据")
    private T data;

    public BaseResponse(String code, String message, T result) {
        super();
        this.code = code;
        this.message = message;
        this.data = result;
    }

    public BaseResponse(ErrorType responseType) {
        super();
        this.code = responseType.getCode();
        this.message = responseType.getMessage();
    }

    public BaseResponse(T result, ErrorType responseType) {
        super();
        this.code = responseType.getCode();
        this.message = responseType.getMessage();
        this.data = result;
    }

    //
    public BaseResponse(ErrorType responseType, String message) {
        this(responseType, message, null);
    }

    //
    public BaseResponse(ErrorType responseType, String message, T result) {
        super();
        this.code = responseType.getCode();
        this.message = responseType.getMessage() + " " + String.valueOf(message);
        this.data = result;
    }

}
